package com.nstar.orderexpress.view
{
	import mx.containers.VBox;
	import mx.containers.HBox;
	import mx.events.FlexEvent;
	import mx.events.DragEvent;
	import mx.managers.DragManager;
	import flash.events.MouseEvent;
	import mx.containers.Panel;
	import mx.core.DragSource;
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import com.nstar.orderexpress.mxml.OrderMenuList;
	import com.nstar.orderexpress.control.OrderMenuListEvent;
	import com.nstar.orderexpress.vo.OrderMenuVO;

	public class ShoppingCartClass extends VBox
	{
		public var orderMenuList:OrderMenuList;

        [Bindable]
        public var numOrderMenus:int=0;
        
        [Bindable]
        private var total:Number = 0;

        private const SHIPPING:Number = 1.99;		
		
		public function ShoppingCartClass()
		{
			//TODO: implement function
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		private function init(event:FlexEvent):void{
			orderMenuList.addEventListener(OrderMenuListEvent.ADD_MENU,orderMenuListHandler);
			orderMenuList.addEventListener(OrderMenuListEvent.DUPLICATE_MENU,orderMenuListHandler);
			orderMenuList.addEventListener(OrderMenuListEvent.MENU_QTY_CHANGE,orderMenuListHandler);
			orderMenuList.addEventListener(OrderMenuListEvent.REMOVE_MENU,orderMenuListHandler);
		}
		
		private function orderMenuListHandler(event:OrderMenuListEvent):void{
            switch (event.type)
            {
                case OrderMenuListEvent.ADD_MENU:
                    event.orderMenu.quantity = 0;  
                    //fall through into the same logic as dup          
                case OrderMenuListEvent.DUPLICATE_MENU:
                	trace(event.orderMenu.quantity);
                    event.orderMenu.quantity++;
                    total += event.orderMenu.price;
                    numOrderMenus++;
                    break;            
                case OrderMenuListEvent.MENU_QTY_CHANGE:
                case OrderMenuListEvent.REMOVE_MENU:
                    var items:Array = orderMenuList.items;
                    total = 0; 
                    numOrderMenus = 0;
                    for (var i:int=0; i < items.length; i++)
                    {
                        var orderMenu:OrderMenuVO = items[i].orderMenu;
                        total += orderMenu.quantity * orderMenu.price;
                        numOrderMenus += orderMenu.quantity;
                    }       
                    break;
                default:
                    break;
            }			
		}
				
	}
}